import { ChunkLib } from "../ChunkLib";
import ShaderLib from "../ShaderLib";

export default class TrailLinkShader {
    public static getVertexShader() {
        return ShaderLib.getDefaultVertexShader();
    }
    public static getFragmentShader() {
        let shader = `
            varying vec2 uvTexcoord;
            uniform float time;
            uniform float segmentLen;
            uniform sampler2D map;
            uniform vec3 v_color;    
            uniform float pathLen;
            uniform float curSegementNo;
            uniform float curSegmentNoStartLen;
            void main(){  
              ${ChunkLib.precision_low}
                vec2 uv = uvTexcoord;
                vec4 fragColor = vec4(0.);
                float curSegmentNoStartUV_x = curSegmentNoStartLen/pathLen;
                float curSegmentNoMaxUV_x = segmentLen/pathLen;
                float calcCurUV_x = curSegmentNoStartUV_x + curSegmentNoMaxUV_x*(uv.x);
                fragColor = texture2D(map, vec2(fract( calcCurUV_x - time ), uv.y));           
                gl_FragColor = fragColor;
            }
        `;
        return shader;
    }
}
